const app = getApp();
let { config } = require('../../../../common/utils/ws/ws-config.js');
let _api_root = config.domain + 'addons/ws_micro_shop/core/web/index.php?r=api/';
Page({
  data: {
    order:{},
    buyer:{},
  },

  onLoad: function (opts) {
    let options = opts || {};
    let isMulti = app.ws_micro_shop_globalData && app.ws_micro_shop_globalData.isMulti;
    this.getOrderInfo(opts.id);
    this.getShopUserInfo(opts.user_id);
    app.loadCurrencyUnit().then(res => {
      this.setData({
        unit: res.unit,
        isMulti
      });
    });
  },

  getOrderInfo(id){
    app.ws_micro_shoprequest({
      url: _api_root + 'order/detail-new',
      data: {
        order_id: id,
      },
      success: res => {
        if (res.code == 0){
          this.setData({
            order: res.data
          })
        }
      }
    })
  },

  getShopUserInfo(user_id){
    let openid = wx.getStorageSync('openid') || wx.getStorageSync('OPENID');
    app.util.request({
      url:'card/record/getShopUserInfo',
      
      data:{
        user_id,
        openid,
      },
      success: res => {
        if(res.data.errno == 0){
          this.setData({
            buyer: res.data.data
          }) 
        }
      }
    })
  },

  goToCard(){
    let { recordid, openid } = this.data.buyer
    if (recordid && openid){
      let url = `common/component/universal-card/pages/customer-info/customer-info?id=${recordid}`;
      app.util.navigateTo(url)
    }
  },

  copyText(e) {
    let text = e.currentTarget.dataset.text;
    wx.setClipboardData({
      data: text,
      success: function () {},
    });
  },

  
});
